/******************************************************************************* 
 *  Copyright 2007 Amazon Technologies, Inc.  
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
 *  
 *  You may not use this file except in compliance with the License. 
 *  You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
 *  This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 *  CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 *  specific language governing permissions and limitations under the License.
 * ***************************************************************************** 
 *    __  _    _  ___ 
 *   (  )( \/\/ )/ __)
 *   /__\ \    / \__ \
 *  (_)(_) \/\/  (___/
 * 
 *  Amazon ECS CSharp Library
 *  API Version: 2007-07-16
 *  Generated: Thu Aug 02 10:15:38 PDT 2007 
 * 
 */

using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Text;


namespace Amazon.ECS.Model
{
    [XmlTypeAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16")]
    [XmlRootAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16", IsNullable = false)]
    public class Offer
    {
    
        private  Merchant merchantField;
        private  Seller sellerField;
        private  OfferAttributes offerAttributesField;
        private  List<OfferListing> offerListingField;

        private  LoyaltyPoints loyaltyPointsField;
        private  Promotions promotionsField;

        /// <summary>
        /// Gets and sets the Merchant property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Merchant")]
        public Merchant Merchant
        {
            get { return this.merchantField ; }
            set { this.merchantField = value; }
        }



        /// <summary>
        /// Sets the Merchant property
        /// </summary>
        /// <param name="merchant">Merchant property</param>
        /// <returns>this instance</returns>
        public Offer WithMerchant(Merchant merchant)
        {
            this.merchantField = merchant;
            return this;
        }



        /// <summary>
        /// Checks if Merchant property is set
        /// </summary>
        /// <returns>true if Merchant property is set</returns>
        public Boolean IsSetMerchant()
        {
            return this.merchantField != null;
        }




        /// <summary>
        /// Gets and sets the Seller property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Seller")]
        public Seller Seller
        {
            get { return this.sellerField ; }
            set { this.sellerField = value; }
        }



        /// <summary>
        /// Sets the Seller property
        /// </summary>
        /// <param name="seller">Seller property</param>
        /// <returns>this instance</returns>
        public Offer WithSeller(Seller seller)
        {
            this.sellerField = seller;
            return this;
        }



        /// <summary>
        /// Checks if Seller property is set
        /// </summary>
        /// <returns>true if Seller property is set</returns>
        public Boolean IsSetSeller()
        {
            return this.sellerField != null;
        }




        /// <summary>
        /// Gets and sets the OfferAttributes property.
        /// </summary>
        [XmlElementAttribute(ElementName = "OfferAttributes")]
        public OfferAttributes OfferAttributes
        {
            get { return this.offerAttributesField ; }
            set { this.offerAttributesField = value; }
        }



        /// <summary>
        /// Sets the OfferAttributes property
        /// </summary>
        /// <param name="offerAttributes">OfferAttributes property</param>
        /// <returns>this instance</returns>
        public Offer WithOfferAttributes(OfferAttributes offerAttributes)
        {
            this.offerAttributesField = offerAttributes;
            return this;
        }



        /// <summary>
        /// Checks if OfferAttributes property is set
        /// </summary>
        /// <returns>true if OfferAttributes property is set</returns>
        public Boolean IsSetOfferAttributes()
        {
            return this.offerAttributesField != null;
        }




        /// <summary>
        /// Gets and sets the OfferListing property.
        /// </summary>
        [XmlElementAttribute(ElementName = "OfferListing")]
        public List<OfferListing> OfferListing
        {
            get
            {
                if (this.offerListingField == null)
                {
                    this.offerListingField = new List<OfferListing>();
                }
                return this.offerListingField;
            }
            set { this.offerListingField =  value; }
        }



        /// <summary>
        /// Sets the OfferListing property
        /// </summary>
        /// <param name="list">OfferListing property</param>
        /// <returns>this instance</returns>
        public Offer WithOfferListing(params OfferListing[] list)
        {
            foreach (OfferListing item in list)
            {
                OfferListing.Add(item);
            }
            return this;
        }          
 


        /// <summary>
        /// Checks if OfferListing property is set
        /// </summary>
        /// <returns>true if OfferListing property is set</returns>
        public Boolean IsSetOfferListing()
        {
            return (OfferListing.Count > 0);
        }


        /// <summary>
        /// Gets and sets the LoyaltyPoints property.
        /// </summary>
        [XmlElementAttribute(ElementName = "LoyaltyPoints")]
        public LoyaltyPoints LoyaltyPoints
        {
            get { return this.loyaltyPointsField ; }
            set { this.loyaltyPointsField = value; }
        }



        /// <summary>
        /// Sets the LoyaltyPoints property
        /// </summary>
        /// <param name="loyaltyPoints">LoyaltyPoints property</param>
        /// <returns>this instance</returns>
        public Offer WithLoyaltyPoints(LoyaltyPoints loyaltyPoints)
        {
            this.loyaltyPointsField = loyaltyPoints;
            return this;
        }



        /// <summary>
        /// Checks if LoyaltyPoints property is set
        /// </summary>
        /// <returns>true if LoyaltyPoints property is set</returns>
        public Boolean IsSetLoyaltyPoints()
        {
            return this.loyaltyPointsField != null;
        }




        /// <summary>
        /// Gets and sets the Promotions property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Promotions")]
        public Promotions Promotions
        {
            get { return this.promotionsField ; }
            set { this.promotionsField = value; }
        }



        /// <summary>
        /// Sets the Promotions property
        /// </summary>
        /// <param name="promotions">Promotions property</param>
        /// <returns>this instance</returns>
        public Offer WithPromotions(Promotions promotions)
        {
            this.promotionsField = promotions;
            return this;
        }



        /// <summary>
        /// Checks if Promotions property is set
        /// </summary>
        /// <returns>true if Promotions property is set</returns>
        public Boolean IsSetPromotions()
        {
            return this.promotionsField != null;
        }






        /// <summary>
        /// XML fragment representation of this object
        /// </summary>
        /// <returns>XML fragment for this object.</returns>
        /// <remarks>
        /// Name for outer tag expected to be set by calling method. 
        /// This fragment returns inner properties representation only
        /// </remarks>


        protected internal String ToXMLFragment() {
            StringBuilder xml = new StringBuilder();
            if (IsSetMerchant()) {
                Merchant  merchant = this.Merchant;
                xml.Append("<Merchant>");
                xml.Append(merchant.ToXMLFragment());
                xml.Append("</Merchant>");
            } 
            if (IsSetSeller()) {
                Seller  seller = this.Seller;
                xml.Append("<Seller>");
                xml.Append(seller.ToXMLFragment());
                xml.Append("</Seller>");
            } 
            if (IsSetOfferAttributes()) {
                OfferAttributes  offerAttributes = this.OfferAttributes;
                xml.Append("<OfferAttributes>");
                xml.Append(offerAttributes.ToXMLFragment());
                xml.Append("</OfferAttributes>");
            } 
            List<OfferListing> offerListingList = this.OfferListing;
            foreach (OfferListing offerListing in offerListingList) {
                xml.Append("<OfferListing>");
                xml.Append(offerListing.ToXMLFragment());
                xml.Append("</OfferListing>");
            }
            if (IsSetLoyaltyPoints()) {
                LoyaltyPoints  loyaltyPoints = this.LoyaltyPoints;
                xml.Append("<LoyaltyPoints>");
                xml.Append(loyaltyPoints.ToXMLFragment());
                xml.Append("</LoyaltyPoints>");
            } 
            if (IsSetPromotions()) {
                Promotions  promotions = this.Promotions;
                xml.Append("<Promotions>");
                xml.Append(promotions.ToXMLFragment());
                xml.Append("</Promotions>");
            } 
            return xml.ToString();
        }

        /**
         * 
         * Escape XML special characters
         */
        private String EscapeXML(String str) {
            StringBuilder sb = new StringBuilder();
            foreach (Char c in str)
            {
                switch (c) {
                case '&':
                    sb.Append("&amp;");
                    break;
                case '<':
                    sb.Append("&lt;");
                    break;
                case '>':
                    sb.Append("&gt;");
                    break;
                case '\'':
                    sb.Append("&#039;");
                    break;
                case '"':
                    sb.Append("&quot;");
                    break;
                default:
                    sb.Append(c);
                    break;
                }
            }
            return sb.ToString();
        }




    }

}